package view;

import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.JTableHeader;
import javax.swing.table.TableColumn;

import server.FirewallSession;

/**
 * Table foe statistics. Two fields statistic name and statistic value.
 */
public class StatisticsTable extends JTable
{
	/**
	 * 
	 */
	private static final long serialVersionUID = -3647839104685398603L;

	/**
	 * server controller
	 */
	protected FirewallSession UI;
	
	/* Current statistics table */
	public static StatisticsTable currentStatisticsTable = null;
	
	/* Table headers */
	private final static String columnNames[] = { "Name", "Number" };
	private final static String rowNames[] = { "Denied sessions", "Accepted sessions" };
	
	public StatisticsTable (FirewallSession ui)
	{
		super(rowNames.length, columnNames.length);
		UI = ui;
		JScrollPane sc = new JScrollPane();
		add(sc);
		
		for(int i = 0; i < rowNames.length; i++)
		{
			setValueAt(rowNames[i], i, 0);
		}
		
		build();
		
		currentStatisticsTable = this;
	}
	
	public JTableHeader getLoggerTableHeader()
	{
		TableColumn column = null;
		for (int i = 0; i < columnNames.length; i++)
		{
		    column = getColumnModel().getColumn(i);
		    column.setHeaderValue(columnNames[i]);
		}
		
		return getTableHeader();	
	}
	
	/**
	 * Cancel cell editing for user.
	 */
	public boolean isCellEditable(int row, int column) 
	{
		return false;
	}
	
	
	/**
	 * Fill the table.
	 */
	public void build()
	{
		Integer denied   = Settings.statsDenied;
		Integer accepted = Settings.statsAccepted;
			
		setValueAt(denied, 0, 1);
		setValueAt(accepted, 1, 1);
	}	
}
